var mongoose=require('mongoose');
var Post=mongoose.model('Post',{
    title:String,
    authors:[String],
    comments:[
        {
            content:String,
            like:Number
        }
    ],
    slice:Array,
    emails:[String],
    todo:[String]
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');

var title='post7';
Post.update({title:title},{
    todo:[0,1,2,3,4,5]
},{upsert:true},(err,r)=>{
    console.log('Update:',err,r);

    Post.update({title:title},{
        $pop:{todo:-1}
    },(e,r)=>{
        console.log('从头部删除：',e,r);

        Post.update({title:title},{
            $pop:{todo:1}
        },(e,r)=>{
            console.log('从尾部删除：',e,r);

            Post.find({title:title},(e,r)=>{
                console.log('Find:\n',e,r);
            })

        });
    });

});


/*
 * $pop:{field:-1}//删除field字段的第一个元素
 * $pop:{field:1}//删除field字段的最后一个元素
 *
 * */





